﻿using oceanho.webapi.factory.httpCore;
using System;
using System.Collections.Generic;
using System.Text;

namespace oceanho.webapi.factory.httpUtility
{
    public sealed class MD5Utility
    {
        public static string Encrypt(string str, MD5Mode mode = MD5Mode.Strongly)
        {
            using (System.Security.Cryptography.MD5CryptoServiceProvider _md5Provider = new System.Security.Cryptography.MD5CryptoServiceProvider())
            {
                byte[] bytes = EncodingUtility.get_bytes(str, Encoding.UTF8);
                bytes = _md5Provider.ComputeHash(bytes);
                StringBuilder _sb = new StringBuilder();
                int s, e;
                s = mode == MD5Mode.Strongly ? 0 : 4;
                e = mode == MD5Mode.Strongly ? 16 : 12;
                for (int i = s; i < e; i++)
                    _sb.Append(bytes[i].ToString("X2"));
                bytes = null;
                return _sb.ToString();
            }
        }
    }
}
